<template>
  <section class="chart-container">
    <el-row>
      <el-col :span="10" :offset="5">
        <div id="chartPie" style="width:600px; height:400px;"></div>
      </el-col>
    </el-row>
    <el-dialog>
      {{list}}
    </el-dialog>
  </section>
</template>

<script>
  import echarts from 'echarts'
  import axios from 'axios'
  export default {
    name: 'Users',
    data() {
      return {
        chartPie: null
      }
    },
    props: {
      list: Array
    },
    methods: {
      drawPieChart () {
        this.chartPie = echarts.init(document.getElementById('chartPie'))
        this.chartPie.setOption({
          title: {
            text: '角色分布',
            x: 'center'
          },
          tooltip: {
            trigger: 'item',
            formatter: "{a}：{b}"
          },
          legend: {
            orient: 'vertical',
            left: 'left'
          },
          series: [
            {
              name: '所属角色',
              type: 'pie',
              radius: '55%',
              center: ['50%', '60%'],
              data: this.list,
              itemStyle: {
                emphasis: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.3)'
                }
              }
            }
          ]
        })
      },
      drawCharts() {
        this.drawPieChart()
      }
    },
    mounted () {
      this.drawCharts()
    },
    updated () {
      this.drawCharts()
    }
  }
</script>

<style scoped>
  .chart-container {
    width: 100%;
    float: left;
  }

  .chart div {
    height: 400px;
    float: left;
  }

  .el-col {
    padding: 30px 20px;
  }
</style>
